/**
* @file Logger.h File Output. 
*
*/
#ifndef _FILE_LOGGER_
#define _FILE_LOGGER_

#include <iostream>
#include <fstream>
#include "TokenHierarchy.h"

using namespace std;

/**
* Outputs strings to a defined file.
* Implemented as singleton.
*/
class FileOutput
{
	public:

		/**
		* Creates and returns a instance of this class.
		*
		*/
		static FileOutput* getInstance();
		
		/**
		* Writes a line to the file.
		* @param line The line which should be write to the file.
		*/
		void writeLine(const char* line);
		
		/**
		* Defines the outputfile.
		* @param filename Path to the file.
		*/
		void setFile(const char* filename);
		
		/**
		* Defines the outputfile and set the cursor at the beginning.
		* @param filename Path to file.
		*/
		void setFileOverWrite(const char* filename);
		
		/**
		* Write a token to the file
		* @param tok A token.
		*/
		void writeToken(Token* tok);

	private:
		static FileOutput* instanz; //!< The single instance
		ofstream file;//!< The outputstream
		
		/**
		* Constructor. Opens a standard file "output.log".
		*/
		FileOutput();
		
		FileOutput( const FileOutput& );

		~FileOutput();

		/**
		* Secures the singelton.
		* Deletes the instance of the singleton.
		*/
		class Secure {
			public: ~Secure() {
				if( FileOutput::instanz != 0 )
					delete FileOutput::instanz;
			}
		};

		friend class Secure;
};

#endif
